package com.pdg.mcplugin.common.baseclasses;

import org.bukkit.entity.Player;
import org.bukkit.permissions.Permissible;

import com.pdg.mcplugin.common.interfaces.PermissionChecker;
import com.pdg.mcplugin.common.interfaces.Permissions;

public class PermissionCheckerBase<E extends PluginBase, P extends Permissions> extends PluginClientBase<E> implements PermissionChecker<P> {

	public PermissionCheckerBase(E thePlugin) {
		super(thePlugin);
	}

	@Override
	public boolean check(Permissible thePermissable, P thePermission) {
		if(thePermissable instanceof Player){
			String thePermissionName = null;
			if(thePermission.isLookup()){
				thePermissionName = getPlugin().getConfig().getString(thePermission.getName(), thePermission.getDefaultLookup());
			}else{
				thePermissionName = thePermission.getName();
			}
			return thePermissable.hasPermission(thePermissionName);
		}else{
			return thePermission.getNonPlayerResult();
		}
	}

}
